package com.ktgj.flight.controller;

import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.flight.common.qunar.QunarService;
import com.ktgj.flight.common.qunar.domain.QnnarFlightSearchPriceResponse;
import com.ktgj.flight.domain.InterfaceEntity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@ControllerAdvice
@RestController
@RequestMapping("/Qunar")
public class QunarController {
    @Autowired
    private QunarService qunarService;

    /**
     * 报价搜索
     * @param map
     * @return
     */
    @PostMapping("/flightSearchPrice")
    public AjaxResult flightSearchPrice(@RequestBody Map<String, Object> map) {
        String OrgAirport = String.valueOf(map.get("OrgAirport"));
        String DstAirport = String.valueOf(map.get("DstAirport"));
        String DepDate = String.valueOf(map.get("DepDate"));
        String FlightNo = String.valueOf(map.get("FlightNo"));
        String BackDate = String.valueOf(map.get("BackDate"));
        QnnarFlightSearchPriceResponse response = qunarService.flightSearchPrice(OrgAirport, DstAirport, DepDate, FlightNo, BackDate);
        return AjaxResult.success(response);
    }

    /**
     * 仓位验价
     * @param request
     * @return
     */
    @PostMapping("/flightCheck")
    public AjaxResult flightCheck(@RequestBody MoFlightCheckRequest request) {
        MoFlightCheckResponse response = qunarService.flightCheck(request);
        return AjaxResult.success(response);
    }

    /**
     * 创建订单
     * @param request
     * @return
     */
    @PostMapping("/orderCreate")
    public AjaxResult orderCreate(@RequestBody MoCreateOrderRequest request) {
        MoCreateOrderResponse response = qunarService.orderCreate(request);
        return AjaxResult.success(response);
    }

    /**
     * 查询订单详情
     * @param request
     * @return
     */
    @PostMapping("/queryOrderInfo")
    public AjaxResult queryOrderInfo(@RequestBody MoQueryOrderRequest request) {
        MoQueryOrderResponse response = qunarService.queryOrderInfo(request);
        return AjaxResult.success(response);
    }

    /**
     * 订单支付前校验
     * @param request
     * @return
     */
    @PostMapping("/orderCheck")
    public AjaxResult orderCheck(@RequestBody MoOrderCheckRequest request) {
        MoOrderCheckResponse response = qunarService.orderCheck(request);
        return AjaxResult.success(response);
    }

    /**
     * 支付订单
     * @param request
     * @return
     */
    @PostMapping("/orderPay")
    public AjaxResult orderPay(@RequestBody MoOrderPayRequest request) {
        MoOrderPayResponse response = qunarService.orderPay(request);
        return AjaxResult.success(response);
    }

    /**
     * 申请退票
     * @param request
     * @return
     */
    @PostMapping("/orderRefund")
    public AjaxResult orderRefund(@RequestBody MoOrderRefundRequest request) {
        MoOrderRefundResponse response = qunarService.orderRefund(request);
        return AjaxResult.success(response);
    }
}
